<!--# include virtual="/ceca_two/modules/user/base/header.html"-->
<style>
body {
  background: #F0F0F0;
}
h1 {
    line-height: 40px;
    margin-bottom: 20px;
}
h1 {
    font-size: 16px;
    color: #333;
}
h1, h2, h3, h4, h5, h6 {
    font-weight: 100;
}
.row{
	margin: 0;
	margin-top: 10px;
}
#noticeWrap{
	background: #FFFFFF;
}
img{
	display: inline-block;
}
#noticeWrap ul li{
	height: 40px;
	line-height: 40px;
}
#noticeWrap ul li:hover{
	background: #CCCCCC;
}
#noticeWrap ul li h2{
	display: inline-block;
	font-size: 14px;
	font-weight: bold;
	vertical-align: middle;
	width: 10%;
	cursor: pointer;
}
#noticeWrap ul li .h2span{
	display: inline-block;
	font-size: 14px;
	vertical-align: middle;
	width: 10%;
	cursor: pointer;
}
#noticeWrap ul li img{
	width: 4%;
}
#noticeWrap ul li span{
	display: inline-block;
	vertical-align: middle;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
#noticeWrap ul li span.cont{
	width: 50%;
}
#noticeWrap ul li span.time{
	width: 14%;
}
#noticeWrap ul li span.read{
	
	width: 10%;
	color: #CCCCCC;
	cursor: pointer;
}
#noticeWrap ul li span.readbtn{
	width: 10%;
	color: #FF0000;
	cursor: pointer;
}
#noticeBox,#noticeBox ul{
	width: 100%;
}
</style>
</head>
<body>
<div class="page-container">
    <div class="row">
        <div class="col-xs-9">
        	<div class="row">
        		<div class="col-xs-12" id="noticeWrap">
        			<p>
        				<h1>我的消息</h1>
        			</p>
        			<hr />
        			<ul id="noticeBox">
        			</ul>
        		</div>
        	</div>
        </div>
    </div>
</div>
<script type="text/html">
	<li>
		<img src="/ceca_two/img/msgnew.png" />
	</li>
</script>

<!--# include virtual="/ceca_two/modules/user/base/footer.html"-->
<script>
	$.ajax({
		type:"post",
		url:"/guidance_service/front/user/userNotice.do",
		async:true,
		data:{
			userId:window.localStorage.getItem("userId")
		},
		success:function(data){
			if(data.resultCode==200){
				var noticeList=data.data;
				var noticeHtml="";
				var createTime="";
				for(var i=0;i<noticeList.length;i++){
					
					if(noticeList[i].updateTime){
						createTime=noticeList[i].updateTime;
					}else if(noticeList[i].createTime){
						createTime=noticeList[i].createTime;
					}
					if(noticeList[i].state=="0"){
						
						noticeHtml=noticeHtml+'<li><img src="/ceca_two/img/msgnew.png" /><h2 onclick="readNotice(\''+noticeList[i].noticeId+'\',this)">'+noticeList[i].noticeTitle+'</h2><span class="cont">'+noticeList[i].noticeContent+'</span><span class="time">'+createTime+'</span><span class="readbtn" onclick="setRead(\''+noticeList[i].noticeId+'\',this)">标为已读</span></li>';
					} else if(noticeList[i].state=="1"){
						noticeHtml=noticeHtml+'<li><img src="/ceca_two/img/msgread.png" /><span class="h2span" onclick="readNotice(\''+noticeList[i].noticeId+'\',this)">'+noticeList[i].noticeTitle+'</span><span class="cont">'+noticeList[i].noticeContent+'</span><span class="time">'+createTime+'</span><span class="read">已读</span></li>';
					}
				}
				$("#noticeBox").html(noticeHtml);
			}
		}
	});
	function setRead(noticeId,obj){
		$.ajax({
			type:"post",
			url:"/guidance_service/front/notice/update.do",
			async:true,
			data:{
				noticeId:noticeId,
				state:1
			},
			success:function(data){
				var noticeObj=data.data;
				$('<img src="/ceca_two/img/msgread.png" /><span class="h2span">'+$(obj).siblings("h2").html()+'</span><span class="cont">'+$(obj).siblings(".cont").html()+'</span><span class="time">'+$(obj).siblings(".time").html()+'</span><span class="read">已读</span>').appendTo($(obj).parent("li").empty());
			}
		});
	}
	function readNotice(noticeId,obj){
		var noticeTitle="";
		if($(obj).siblings("h2").length>0){
			noticeTitle=$(obj).siblings("h2").html();
		}else if($(obj).siblings(".h2span").length>0){
			
			noticeTitle=$(obj).siblings(".h2span").html();
		}
		window.notice={
			noticeTitle:noticeTitle,
			noticeCont:$(obj).siblings(".cont").html()
		};
		console.log(notice);
		console.log("notice");
		window.location.href="noticeDetail.html?noticeId="+noticeId;
	}
</script>
